package com.cysoft.starter.log.core.configuration;


import com.cysoft.starter.log.config.LogAutoConfiguration;
import com.cysoft.starter.log.core.aspect.LogAspect;
import com.cysoft.starter.log.core.properties.OperateLogProperties;
import com.cysoft.starter.log.core.repository.impl.EventRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 玖零
 * @version v0.0.1
 * @project cysoft-spring-boot-starter-log
 * @package com.cysoft.starter.log.core.configuration
 * @date 2025-02-06 21:26
 * @desc Event方式,不在日志记录中对日志进行操作,具体的实现交给监听者自行实现
 */
@Slf4j
@Configuration
@ConditionalOnBean(name = "eventConfiguration")
@AutoConfigureAfter(LogAutoConfiguration.class)
public class EventConfiguration  {


    /**
     * 操作日志配置信息
     */
    private final OperateLogProperties operateLogProperties;

    /**
     * Spring上下文
     */
    private final ApplicationContext applicationContext;

    /**
     * event日志切面配置 构造方法
     * @param operateLogProperties
     */
    public EventConfiguration(OperateLogProperties operateLogProperties,ApplicationContext applicationContext) {
        this.operateLogProperties = operateLogProperties;
        this.applicationContext = applicationContext;
    }

    @Bean
    public LogAspect eventLogAspect(){
        log.info("******************开始初始化eventLogAspect******************");
        log.info("开始构建event日志切面");
        LogAspect logAspect = new LogAspect(new EventRepository(applicationContext), operateLogProperties);
        log.info("event日志切面构建成功，日志切面对象: {}", logAspect);
        return logAspect;
    }

}
